<?php

declare (strict_types=1);
namespace App\Model;

use Hyperf\DbConnection\Model\Model;
/**
 * @property int $id 
 * @property int $male_id 
 * @property int $female_id 
 * @property int $status 
 * @property \Carbon\Carbon $created_at 
 * @property \Carbon\Carbon $updated_at 
 */
class InviteVideoLog extends Model
{
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'invite_video_log';
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [];
    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = ['id' => 'integer', 'male_id' => 'integer', 'female_id' => 'integer', 'status' => 'integer', 'created_at' => 'datetime', 'updated_at' => 'datetime'];

    //邀约阶段
    const STATUS_INVITE = 0;

    //未接听-女生拒绝
    const STATUS_FEMALE_REFUSE = 2;

    //未接听-男生拒绝
    const STATUS_MALE_REFUSE = 1;

    //完成
    const STATUS_FINISH = 3;

    //未接听-已失效
    const STATUS_NO_ANSWER = 4;

    //接听中
    const STATUS_ANSWERING = 5;

    /**
     * 更新状态
     * @param $maleId
     * @param $femaleId
     * @param $status
     * @return int
     */
    public static function updateStatus($maleId,$femaleId,$status): int
    {
        return self::where([
            ['male_id','=',$maleId],
            ['female_id','=',$femaleId],
//            ['status','=',InviteVideoLog::STATUS_INVITE]
        ])->orderBy('id','desc')->update(['status'=> $status]);
    }


    /**
     * 获取今天接听了多少视频邀约
     * @param $userId
     * @return int
     */
    public static function getInviteVideoCountToday($userId): int
    {
        return self::where([
            ['male_id','=',$userId],
            ['status','=',self::STATUS_FINISH],
            ['created_at','>=',date('Y-m-d ').'00:00:00'],
            ['created_at','<=',date('Y-m-d ').'23:59:59'],
        ])->count() ?? 0;
    }

    /**
     * 获取总共接听了多少视频邀约
     * @param $userId
     * @return int
     */
    public static function getInviteVideoCountTotal($userId): int
    {
        return self::where([
            ['male_id','=',$userId],
            ['status','=',self::STATUS_FINISH]
        ])->count() ?? 0;
    }

    /**
     * 获取今天拒绝了多少视频邀约
     * @param $userId
     * @return int
     */
    public static function getInviteVideoRefuseCountToday($userId): int
    {
        return self::where([
            ['male_id','=',$userId],
            ['status','=',self::STATUS_MALE_REFUSE],
            ['created_at','>=',date('Y-m-d ').'00:00:00'],
            ['created_at','<=',date('Y-m-d ').'23:59:59'],
        ])->count() ?? 0;
    }

    /**
     * 获取今日已经接听的
     * @param $userId
     * @return int
     */
    public static function getFemaleInviteVideoRefuseCountToday($userId): int
    {
        return self::where([
            ['female_id','=',$userId],
            ['status','=',self::STATUS_FINISH],
            ['created_at','>=',date('Y-m-d ').'00:00:00'],
            ['created_at','<=',date('Y-m-d ').'23:59:59'],
        ])->count() ?? 0;
    }

    /**
     * 获取还在邀约的视频
     * @return array
     */
    public static function getInviteStatusData(): array
    {
        return self::where([
            ['status','=',self::STATUS_INVITE],
        ])->get()->toArray();
    }
}